<template>
  <el-container style="height: 100vh">
    <el-aside width="200px" style="background-color: #304156">
      <div class="title">选课管理系统</div>
      <el-menu :default-openeds="['1']">
        <el-submenu :index="i+''" v-for="(item,i) in menus" :key="i">
          <template slot="title"><i :class="item.icon"></i>{{item.menuName}}</template>
          <el-menu-item :index="k+'-'+i" v-for="(list,k) in item.children" :key="k" @click="go(list.path)">{{list.menuName}}</el-menu-item>
        </el-submenu>
        <!-- <el-submenu index="3">
          <template slot="title"
            ><i class="el-icon-setting"></i>系统管理</template
          >
          <el-menu-item index="3-1">用户管理</el-menu-item>
          <el-menu-item index="3-2">菜单管理</el-menu-item>
        </el-submenu> -->
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <span>{{$store.getters.getName}}</span>
        <span @click="logout" style="margin-left: 20px; cursor: pointer"
          >退出</span
        >
      </el-header>

      <el-main>
        <router-view />
       </el-main>
    </el-container>
  </el-container>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      menus:[
        {
          path:null,
          menuName:'课程管理',
          icon:'el-icon-menu',
          children:[
            {
              path:'/class',
              menuName:'课程列表',
              icon:null,
            }
          ]
        },
        {
          path:null,
          menuName:'系统管理',
          icon:'el-icon-setting',
          children:[
            {
              path:'/user',
              menuName:'用户管理',
              icon:null,
            },
            {
              path:'/menus',
              menuName:'菜单管理',
              icon:null,
            }
          ]
        }
      ],
     
    };
  },
  methods: {
    go(path){
      this.$router.push(path)
    },
    logout() {
      this.$store.commit("REMOVE_TOKEN");
      axios.post("api/logout").then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: res.data.message,
            type: "success",
          });
          this.$router.push("/login");
        }
      });
    }
  },
};
</script>
<style>
.title {
  height: 60px;
  line-height: 60px;
  color: #fff;
  font-weight: bold;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}
.el-aside .el-menu {
  background-color: #1f2d3d;
  color: #fff;
  border-right: none;
}
.el-aside .el-menu .el-submenu__title {
  color: #fff;
  text-align: left;
}
.el-submenu__title:hover {
  background-color: rgba(0, 0, 0, 0.06) !important;
}
.el-aside .el-menu .el-menu-item {
  color: #fff;
  text-align: left;
}
.el-menu-item:focus,
.el-menu-item:hover {
  background-color: #001528 !important;
}
.el-aside {
  color: #333;
}
.el-aside .el-menu .el-menu-item.is-active {
  color: #409eff;
}
.el-header {
  background-color: #fff;
  border-bottom: 1px solid #d8dce5;
  -webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12),
    0 0 3px 0 rgba(0, 0, 0, 0.04);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 0 3px 0 rgba(0, 0, 0, 0.04);
}
</style>
